/**
 * 
 */
package leetCode;

import java.util.Arrays;

/**
 * @author zhong
 *
 */
public class MinimumIncrementtoMakeArrayUnique {
	public int minIncrementForUnique(int[] A) {
		if (A == null || A.length < 1) {
			return 0;
		}
		Arrays.sort(A);
		int last = A[0];
		int cnt = 0;
		for (int j = 1; j < A.length; j++) {
			int i = A[j];
			while (i <= last) {
				cnt++;
				i++;
			}
			last = i;
		}
		return cnt;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int A[] = { 3, 2, 1, 2, 1, 7 };
		System.out.println(new MinimumIncrementtoMakeArrayUnique().minIncrementForUnique(A));
	}

}
